import { useRoute, useRouter } from "vue-router"
import { reactive, watch } from "vue"
import { Message as message } from "@arco-design/web-vue"

export default function useCubePage() {
  const router = useRouter()
  const route = useRoute()

  const dataset = reactive({
    id: "",
    name: ""
  })

  // 返回
  const handleBack = (backUrl) => {
    router.push(backUrl || "/")
  }

  watch(
    () => route.path,
    (path) => {
      if (path !== "/cubeeditor") return
      const { id } = route.query
      if (id) {
        dataset.id = id
      } else {
        message.error("没有请求参数，即将关闭此页面！")
      }
    },
    { immediate: true }
  )

  return {
    dataset,
    handleBack
  }
}
